package com.square.service.auth.provider.controller.rpc;

import com.baomidou.mybatisplus.extension.api.R;
import com.square.service.auth.provider.service.AuthService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 认证控制层
 * 内网提供消费者调用
 *
 * @author : 王苏
 * @since : 2021/4/21 10:43
 */
@RestController
@RequestMapping("/rpc/auth")
public class AuthController {

    @Resource
    private AuthService authService;

    /**
     * 登录认证
     *
     * @param token
     * @return
     */
    @GetMapping("/doGetAuthenticationInfo")
    public R<?> doGetAuthenticationInfo(@RequestParam("token") String token) {
        return authService.doGetAuthenticationInfo(token);
    }

    /**
     * 角色认证
     *
     * @param userKey
     * @param value
     * @return
     */
    @GetMapping("/doGetAuthorizationInfoForRoles")
    public R<?> doGetAuthorizationInfoForRoles(@RequestParam("userKey") String userKey, @RequestParam("value") String[] value) {
        return authService.doGetAuthorizationInfoForRoles(userKey, value);
    }

    /**
     * 权限认证
     *
     * @param userKey
     * @param value
     * @return
     */
    @GetMapping("/doGetAuthorizationInfoForPermissions")
    public R<?> doGetAuthorizationInfoForPermissions(@RequestParam("userKey") String userKey, @RequestParam("value") String[] value) {
        return authService.doGetAuthorizationInfoForPermissions(userKey, value);
    }
}
